<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<canvas id="myCanvas" width="500" height="500"></canvas>

</body>
<script>
    // 获取Canvas元素和上下文
    var canvas = document.getElementById("myCanvas");
    var ctx = canvas.getContext("2d");

    // 定义小方块的位置和尺寸
    var squares = [
        { x: 50, y: 50, size: 30 },
        { x: 150, y: 100, size: 30 },
        { x: 250, y: 150, size: 30 },
        { x: 350, y: 200, size: 30 }
    ];

    // 绘制小方块
    squares.forEach(function(square) {
        ctx.fillStyle = "blue";
        ctx.fillRect(square.x, square.y, square.size, square.size);
    });

    // 绘制直线连接小方块
    ctx.beginPath();
    ctx.moveTo(squares[0].x + squares[0].size / 2, squares[0].y + squares[0].size / 2);
    for (var i = 1; i < squares.length; i++) {
        var square = squares[i];
        ctx.lineTo(square.x + square.size / 2, square.y + square.size / 2);
    }
    ctx.stroke();
</script>
</html>

